home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 6 / The Arsenal Files 6 (Arsenal Computer).ISO / os2bbs / fbrow112.zip / FBROWSER.MEX < prev    next >
Text File  |  1996-03-23  |  24KB  |  823 lines

  1. //======================== Interface 1.12 ============================
  2. // Program: MEX Filebrowser
  3. //
  4. // Created in 1995 by Jonas Öberg, 2:204/466
  5. // Modified 2 Oct 1995 by Neil Walker, 2:2500/509
  6. //
  7. // Thanks to:
  8. //    The author of XGetCh() used by this program
  9. //    Werner Schlagnitweit for the mex program f-titles, great program
  10. //        although it's a little slow with the 3d stuff.
  11. //
  12. // -=Public Domain=-
  13. // Drastically altered by Jim Woodward 1:268/412, thus renamed
  14. //
  15. //  on 12/10/95 I, Jim Woodward, incorporated Herman Freeman's
  16. //              viewrar.mex program into fbrowser.mex
  17. //
  18. // on 12/19/95
  19. // Added: S for taglist  inspired by:  Ole Aggerholm, 2:238/11.0
  20. //
  21. // on 01/23/96  Redefined pageup/down keys to +/- keys, thus
  22. // enabling me to use 'q' for quitting the program.
  23. //
  24. // Check for empty filearea error corrected by: Ole Aggerholm
  25. // on 02/29/96 fbrowser will now skip blank lines in files.bbs
  26. // on 03/02/96 added support for TTY users
  27. // ******** below lines refer to lines in your files.bbs file *****
  28. // on 03/05/96 lines with something in first column and a blank (space)
  29. //      in the 2nd column will be treated as non-printing
  30. //      comment lines.
  31. // on 03/11/96:107 lines with a '-' or ' ' in column 1 will
  32. //      be acomment line that are printed on remote screen.
  33. //      if column 1 and column 2 are '-' , then
  34. //      the next line will line 1 of a new page.
  35. // *********                                                  ******
  36.  
  37. #include <\max\m\max.mh>
  38. #include <\max\m\max_menu.mh>
  39. #include <\max\m\prm.mh>
  40. #include <\max\m\xgetch.mh>
  41.  
  42. //below added by jaw from viewrar.mex
  43.  
  44. #define ARCH_SIGN              "\x52\x61\x72\x21\x1a\x07"
  45. #define ARCH_WHICH             "Display the contents of which archive? "
  46. #define ARCH_TITLE             " Name                Size   Packed   Date   Time"
  47. #define ARCH_LINE              "-------------------------------------------------"
  48.  
  49.   unsigned int:   HeadCRC;
  50.   unsigned char:  HeadType;
  51.   unsigned int:   Flags;
  52.   unsigned int:   HeadSize;
  53.   unsigned long:  PackSize;
  54.   unsigned long:  UnpSize;
  55.   unsigned char:  HostOS;
  56.   unsigned long:  FileCRC;
  57.   unsigned int:   FYear;
  58.   unsigned int:   FMonth;
  59.   unsigned int:   FDay;
  60.   unsigned int:   FHour;
  61.   unsigned int:   FMin;
  62.   unsigned int:   FSec;
  63.   unsigned char:  UnpVer;
  64.   unsigned char:  Method;
  65.   unsigned int:   NameSize;
  66.   unsigned long:  FileAttr;
  67.   unsigned long:  NBPos,nblock;
  68.   string:         Afname;
  69.  
  70. //    end of viewrar.mex's variables etc
  71.  
  72. //========================= Global variables =========================
  73. int:     page,fhandle;
  74. // Page: The page number we're currently working on
  75. // Fhandle: File handle for files.bbs
  76. long: end;         // file variable, end of file
  77. array [1..100] of long: old;     //up to 100 pages allowed
  78. array [0..1] of string: descr_colour;
  79. int: act_page;     // active page, i.e. page on screen
  80. int: linenumber;  // line number
  81. int: file_end;  //     0 means reached end of file
  82. int: fd;       // file handle
  83.  
  84. //========================= Page structure ===========================
  85. struct _page
  86. // Lastfile: This integer defines the last file on this page, in most cases
  87. //           this should equal to 16, except for the last page
  88. // Filename: Contains the filename, BUT!  if filename="", <desc> contains
  89. //           a description that is continued from the last file.
  90. //           And, if filename="z", <desc> is a comment.
  91. // Size: Size of the file
  92. // Date: Date of file as a string
  93. // Desc: Description or comment
  94. // Tagged: TRUE if file is tagged and FALSE if not
  95. {
  96.     array [1..28] of string: filename;
  97.     array [1..28] of long: size;
  98.     array [1..28] of string: date;
  99.     array [1..28] of string: desc;
  100.     array [1..28] of int: tagged;
  101. } ;
  102. struct _page: p;
  103. array [1..17] of int: real;
  104. int: fnum;
  105.  
  106. // Functions
  107.  
  108. // main function
  109. void do_it();
  110. //
  111. void view_cont(string: filespec); // added by jaw 12/11/95
  112. //                                   from viewrar.mex
  113. void settagged();
  114. void checktagged();
  115. // Inserts tagged files in Maximus que.
  116.  
  117. void printpage();
  118. // Redraws screen
  119.  
  120. int getpage();
  121. // Reads Page of files
  122.  
  123. string filesbbspath();
  124. // Returns:  Path to files.bbs file
  125. // Description:  Also checks to see if files.bbs is valid (exists) and
  126. //               if not, returns ""
  127.  
  128.  
  129. void clearscreen();
  130. // Clear display screen
  131.  
  132. void clearpage();
  133. // Clear page
  134.  
  135.  
  136. int processcommands();
  137. // Processes keystrokes
  138. // Returns 0 if exit, 2 if new screen    etc
  139.  
  140. int readline(int: rpage);
  141. // Reads a line from fhandle and processes it if ok.
  142. // Returns 0 if Ok, 1 if EOF.
  143.  
  144. int processline();
  145. // Processes one line of text, checks filename etc
  146.  
  147. //======================== Implementation ===========================
  148.  
  149. int processline(int: plinenumber,string: line)
  150. // Processes one line of text, checks filename etc
  151. {
  152.     int: len,pos, k;
  153.     string: fname,desc,temp;
  154.     struct _stamp: date;
  155.  
  156.  
  157.     k:=stridx(line,1,' ');
  158.     if ((line[1]='-' or line[1]=' ') and farea.attribs<>7)
  159.     {
  160.         p.filename[plinenumber]:="z";
  161.         if (line[2]='-')
  162.         {
  163.             p.desc[plinenumber]:=" ";
  164.             return 17;
  165.         }
  166.         p.desc[plinenumber]:=substr(line,1,79);
  167.         plinenumber:=plinenumber+1;
  168.         if (plinenumber=17)
  169.         {
  170.             plinenumber:=18;
  171.         }
  172.         return plinenumber;
  173.     }
  174.     if (k =0)
  175.     {
  176.         fname:=line;     // Checks for desc.
  177.         temp:=line + " No description given to File Browser!";
  178.         line:=temp;
  179.     }
  180.     else fname:=substr(line,1,k-1);
  181.     if (strlen(line)>2)
  182.     {
  183.         {
  184.             // This is a file!
  185.             p.filename[plinenumber]:=fname;
  186.             real[fnum]:=plinenumber;
  187.             fnum:=fnum+1;
  188.             temp:=farea.downpath+fname;
  189.             if (fileexists(temp)=TRUE)
  190.             {
  191.                 p.size[plinenumber]:=filesize(temp);
  192.                 filedate(temp,date);
  193. // ddmmyy             p.date[plinenumber]:=strpadleft(itostr(date.date.day),2,'0') + "/" + strpadleft(itostr(date.date.month),2,'0') + "/" +strpadleft(itostr(date.date.year+ 80),2,'0');
  194.                 p.date[plinenumber]:=strpadleft(itostr(date.date.month),2,'0') + "/" + strpadleft(itostr(date.date.day),2,'0') + "/" +strpadleft(itostr(date.date.year+ 80),2,'0');
  195.             }
  196.             else
  197.             {
  198.                 p.size[plinenumber]:=0; // Missing
  199.                 p.date[plinenumber]:=" Offline";
  200.             }
  201.             if ((pos:=stridx(line,1,' '))>0)
  202.             {
  203.                 p.desc[plinenumber]:=substr(line,pos+1,strlen(line)-pos+1);
  204.                 p.desc[plinenumber]:=strtrim(p.desc[plinenumber],"    ");
  205.                 if (strlen(p.desc[plinenumber])<46)
  206.                     plinenumber:=plinenumber+1;
  207.                 else   // Split line
  208.                 {
  209.                     desc:=p.desc[plinenumber];
  210.                     do
  211.                     {
  212.                     pos:=stridx(desc,1,158);
  213.                     if (pos=0)
  214.                       {
  215.                         desc:=strtrim(desc,"    ");
  216.                         pos:=1;
  217.                         if (desc[45]=' ' and desc[44]<>' ') pos:=44;
  218.                         else
  219.                         {
  220.                             pos:=45;
  221.                             do
  222.                             {
  223.                                 pos:=pos-1;
  224.                             }  while (pos>1 and desc[pos]<>' ');
  225.                             if (pos=1) pos:=44;
  226.                         }
  227.                         p.desc[plinenumber]:=substr(desc,1,pos);
  228.                         desc:=substr(desc,pos+1,strlen(desc)-pos);
  229.                         desc:=strtrim(desc,"    ");
  230.                         plinenumber:=plinenumber+1;
  231.                       }
  232.                       else
  233.                       {
  234.                         p.desc[plinenumber]:=substr(desc,1,pos-1);
  235.                         desc:=substr(desc,pos+1,strlen(desc)-pos+1);
  236.                         plinenumber:=plinenumber+1;
  237.                       }
  238.                     } while (strlen(desc)>45 and plinenumber<18);
  239.                     if (strlen(desc)>0 and plinenumber<16)
  240.                     {
  241.                         p.desc[plinenumber]:=desc;
  242.                         plinenumber:=plinenumber+1;
  243.                     }
  244.                 }
  245.             }
  246.         }
  247.         if (plinenumber>17)
  248.         {
  249.             p.filename[real[fnum-1]]:="";
  250.             real[fnum]:=33;
  251.         }
  252.     }
  253.     return plinenumber;
  254. }
  255.  
  256. int getpage(int: rpage)     // a blank line within files.bbs
  257. {                           // will cause display to stop there
  258.     int: result,i;
  259.     string: line, line2,line3;
  260.     long: first, tmp1,tmp2;
  261.     string: temp;
  262.  
  263.     for (i:=1; i<18; i:=i+1)  real[i]:=32;
  264.     fnum:=1;
  265.     if (rpage=2 and file_end=0)    // already on last page
  266.     {
  267.         return 0;
  268.     }
  269.     if (act_page=1 and rpage=0)    // already at the first file
  270.     {
  271.         return 0;
  272.     }
  273.     settagged();
  274.     linenumber:=1;
  275.     clearscreen();
  276.     clearpage();
  277.     fhandle:=open(filesbbspath(), IOPEN_READ);
  278.     if (rpage = 2 )
  279.     {
  280.         act_page:=act_page+1;
  281.         seek(fhandle,end,SEEK_SET);
  282.         old[act_page]:=tell(fhandle);
  283.     }
  284.     else if (rpage=1 or rpage=3)
  285.     {
  286.         seek(fhandle,0,SEEK_SET);
  287.         act_page:=1;
  288.         old[1]:=tell(fhandle);
  289.     }
  290.     else if (rpage=0)
  291.     {
  292.         if (act_page>1)    act_page:=act_page-1;
  293.         seek(fhandle,old[act_page],SEEK_SET);
  294.     }
  295.     else if (rpage=4)
  296.     {
  297.         seek(fhandle,old[act_page],SEEK_SET);
  298.     }
  299.     file_end:=1;
  300.     i:=0;
  301.     do       // Until i >= 16
  302.     {
  303.         first:=tell(fhandle);
  304.         result:=readln(fhandle, line);
  305.         if (result>511)    readln(fhandle,temp);
  306.         if (result=0)
  307.         {
  308.             line:="  ";
  309.             result:=2;
  310.         }
  311.     if(farea.attribs=7 or farea.attribs=71)       // CD
  312.     {
  313.         tmp1:=tell(fhandle);
  314.         tmp2:=readln(fhandle,line2);
  315.         while (line2[1]=' ' and strlen(line2)>0 )
  316.         {
  317.             line3:=strtrim(line2,"             ");
  318.             line:=line+"\x9e"+line3;
  319.             tmp1:=tell(fhandle);
  320.             tmp2:=readln(fhandle,line2);
  321.         }
  322.           {
  323.             seek(fhandle,tmp1,SEEK_SET);
  324.           }
  325.     }
  326.         if (result>0) // EOF?
  327.         {
  328.             i:=processline(linenumber,line);       //i is NOW the next free line
  329.             if (i<17)
  330.             {
  331.                 end:=tell(fhandle);
  332.                 linenumber:=i;
  333.             }
  334.             else if (i=17)
  335.             {
  336.                 result:=0;
  337.                 end:=tell(fhandle);
  338.                 linenumber:=17;
  339.                 result:=readln(fhandle, line);
  340.                 if (result<0)
  341.                 {
  342.                 file_end:=0;
  343.                 close(fhandle);
  344.                 return 1;
  345.                 }
  346.                 else  seek(fhandle, end, SEEK_SET);
  347.             }
  348.             else      // needed to keep last display to not overlap
  349.             {
  350.             result:=0;
  351.             linenumber:=linenumber-1;
  352.             }
  353.         }
  354.         else        // done with this screen
  355.         {
  356.             file_end:=0;
  357.             if (linenumber>16) linenumber:=16;
  358.             i:=17;
  359.         }
  360.     } while(i<17);
  361.     close(fhandle);
  362.     return 1;
  363. }
  364.  
  365. int processcommands()
  366. // Processes keystrokes
  367. {
  368.     int: exit,select,choice,num,posn,flags;
  369.     char: tempint;
  370.     string: filename;
  371.  
  372.     exit:=FALSE;
  373.     tempint:=1;
  374.     choice:=1;
  375.  
  376.     if (p.filename[choice]<>"" and p.filename[choice]<>" ") num:=choice;
  377.     // Find first file in list.
  378.     while (p.filename[num]="z") num:=num+1;
  379.     if (num=17)
  380.     {
  381.         num:=16;
  382.         p.filename[num]:="";
  383.     }
  384.     do
  385.     {
  386.         // Print filename in Yellow with blue background
  387.         print (AVATAR_GOTO, (char)(num+2),(char)1, COL_YELLOWONBLUE, p.filename[num]);
  388.         if (p.tagged[num]=TRUE) print(AVATAR_GOTO, (char)(num+2),(char)13,COL_WHITE, "*");
  389.         else print (AVATAR_GOTO, (char)(num+2),(char)13,COL_WHITE, " ");
  390.  
  391.         // Get a key
  392.         choice:=xgetch();
  393.  
  394.         if (choice=X_UP or choice='8')
  395.         // Up
  396.         {
  397.             print (AVATAR_GOTO, (char)(num+2),(char)1, COL_LGREEN,p.filename[num]);
  398.             select:=num;
  399.             choice:=0;
  400.             do // Find the first file
  401.             {
  402.                 select:=select-1;
  403.                 if (select=0) return 0;
  404.                 if (p.filename[select]<>"" and p.filename[select]<>" " and p.filename[select]<>"z")
  405.                     choice:=select;
  406.             }
  407.             while (choice=0);
  408.             num:=choice;
  409.         }
  410.         else if (choice='C' or choice='c') // Chng protocol
  411.         {
  412.             print(AVATAR_CLS);
  413.             menu_cmd(MNU_CHG_PROTOCOL,"");
  414.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  415.             return 4;
  416.         }
  417.         else if (choice=X_DOWN or choice='2')
  418.         // Down
  419.         {
  420.             print (AVATAR_GOTO, (char)(num+2),(char)1, COL_LGREEN,p.filename[num]);
  421.             select:=num;
  422.             choice:=0;
  423.             do // Find the first file
  424.             {
  425.                 select:=select+1;
  426.                 if (select=17) return 2;
  427.                 if (p.filename[select]<>"" and p.filename[select]<>" " and p.filename[select]<>"z") choice:=select;
  428.             }
  429.             while (choice=0);
  430.             num:=choice;
  431.         }
  432.         else if (choice=27 or choice='q' or choice='Q' or choice='n' or choice='N') exit:=TRUE;
  433.         // Escape
  434.         else if (choice=32) // Spacebar
  435.         if (p.tagged[num]=TRUE) p.tagged[num]:=FALSE;
  436.         else p.tagged[num]:=TRUE;
  437.  
  438.  
  439.         else if (choice='+' or choice='3' or choice=13) // PgDn
  440.         {
  441.             return 2; // Draw next page
  442.         }
  443.         else if (choice='-' or choice='9') // PgUp
  444.         {
  445.             return 0; // Draw previous page
  446.         }
  447.         else if (choice=X_HOME or choice='7' or choice='*') // Home
  448.         {
  449.             return 3; // Draw new page
  450.         }
  451.         else if (choice=']' or choice='[') // Next file area
  452.         {
  453.                 clearscreen();
  454.                 file_area();
  455.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  456.             return 3; // Draw first page
  457.         }
  458.         else if (choice='U' or choice='u') // Upload
  459.         {
  460.             print(AVATAR_CLS);
  461.             menu_cmd(MNU_FILE_UPLOAD,"");
  462.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  463.             return 4;
  464.         }
  465.         else if (choice='S' or choice='s') // List tagged files
  466.         {
  467.             print(AVATAR_CLS);
  468.             settagged();
  469.             if (tag_queue_size()<>0)
  470.             {
  471.          //       TagList();
  472.                   menu_cmd(MNU_FILE_TAG,"");
  473.             }
  474.             else
  475.             {
  476.                 display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  477.                 print (AVATAR_GOTO, (char)(4),(char)2,COL_WHITE,"Your Tag list is empty!");
  478.                 getch();
  479.             }
  480.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  481.             return 4;
  482.         }
  483.         else if (choice='V' or choice='v') //
  484.         {
  485.             print(AVATAR_CLS);
  486.             filename:=p.filename[num];
  487.             view_cont(filename);
  488.             print( COL_LRED, "Tap a key to continue");
  489.             getch();
  490.             close(fd);
  491.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  492.             return 4;
  493.         }
  494.         else if (choice='D' or choice='d')
  495.         {
  496.             print(AVATAR_CLS);
  497.             settagged();
  498.             if (tag_queue_size()<>0)
  499.             {
  500.                 menu_cmd(MNU_FILE_DOWNLOAD,"");
  501.             }
  502.             else
  503.             {
  504.                 tag_queue_file(farea.downpath+p.filename[num],0);
  505.                 menu_cmd(MNU_FILE_DOWNLOAD,"");
  506.             }
  507.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  508.             return 4;
  509.         }
  510.     }
  511.     while (exit=FALSE);
  512.     return -1;
  513. }
  514.  
  515. void clearscreen()
  516. // Clear display screen
  517. {
  518.     int: count;
  519.  
  520.     print (AVATAR_GOTO, (char)2, (char)1);
  521.     for (count:=0;count<16;count:=count+1) print(AVATAR_DOWN AVATAR_CLEOL);
  522.  
  523.     print (AVATAR_GOTO, (char)3, (char)1); // Restore cursor
  524. }
  525.  
  526.  
  527. string filesbbspath()
  528. // Returns:  Path and filename of files.bbs compatible file
  529. // Description:  Also checks to see if files.bbs is valid (exists) and
  530. //               if not, returns ""
  531. // *** Modified function *** (Neil Walker 2 Oct 1995)
  532.  
  533. {
  534.     string: temp;
  535.     
  536.     if (farea.filesbbs="") temp:=farea.downpath+"files.bbs";
  537.     else temp:=farea.filesbbs;
  538.     
  539.     if (fileexists(temp)=FALSE) temp:="";
  540.  
  541.     return temp;
  542. }
  543.  
  544. void printpage()
  545. // Redraws screen
  546. {
  547.     int: pos,i;
  548.     string: colour;
  549.  
  550.     clearscreen();
  551.     checktagged();
  552.     i:=1;
  553.     if (linenumber>16) linenumber:=16;
  554.     print (COL_LBLUE,AVATAR_GOTO, (char)1, (char)(38-strlen(farea.descript)/2), "╣ ", COL_LRED, farea.descript, COL_LBLUE, " ╠", AVATAR_GOTO, (char)3, (char)1);
  555.     print (COL_LBLUE,AVATAR_GOTO, (char)19, (char)48,COL_LGREEN,strpad(ltostr(timeleft()),4,' ')," ");
  556.     print (AVATAR_GOTO, (char)2, (char)61, COL_YELLOW, strpad(itostr(act_page),3,' '),"\n");
  557.     for (pos:=1;pos<=linenumber;pos:=pos+1)
  558.     {
  559.         if (strlen(p.filename[pos])>0)     // alternates desc colours
  560.         {
  561.         i:=i+1;
  562.         colour:=descr_colour[i%2];
  563.         }
  564.         if (p.filename[pos]="z")
  565.         {
  566.             print (COL_GRAY, p.desc[pos]);
  567.         }
  568.         else if (p.filename[pos]="") print (colour, AVATAR_GOTO, (char)(pos+2),(char)35,p.desc[pos]);
  569.         else
  570.         {
  571.             print (COL_LGREEN, p.filename[pos],strpad("",12-strlen(p.filename[pos]),' '));
  572.             if (p.tagged[pos]=TRUE) print (COL_WHITE,"*");
  573.             else print (" ");
  574.             print (COL_YELLOW, strpadleft(ltostr(p.size[pos]),9,' '),"  ",
  575.             COL_LGREEN, p.date[pos],"  ",colour, p.desc[pos]);
  576.  
  577.         }
  578.         print("\n");
  579.     }
  580. }
  581.  
  582. void settagged()
  583. // Inserts tagged files in Maximus que.
  584. {
  585.     int: pos,i,flgs, ok,tag;
  586.     string: tagname,testname;
  587.  
  588.     ok:=tag_queue_size();
  589.     for (pos:=1;pos<17;pos:=pos+1)
  590.     if (p.tagged[pos]=TRUE)
  591.     {
  592.         tag:=0;
  593.         testname:=strupper(farea.downpath+p.filename[pos]);
  594.         for (i:=0;i<ok;i:=i+1)
  595.         {
  596.             tag_get_name(i, flgs,tagname);
  597.             if (tagname=testname) tag:=1;
  598.         }
  599.         if (tag=0) tag_queue_file(farea.downpath+p.filename[pos],0);
  600.     }
  601.     else
  602.     {
  603.         testname:=strupper(farea.downpath+p.filename[pos]);
  604.         for (i:=0;i<ok;i:=i+1)
  605.         {
  606.             tag_get_name(i, flgs,tagname);
  607.             if (tagname=testname) tag_dequeue_file(i);
  608.         }
  609.     }
  610. }
  611. void do_it()
  612. {
  613.     int: k;
  614.  
  615.     k:=1;
  616.     do {
  617.         k:=getpage(k);
  618.         if (k=1) printpage();
  619.         do
  620.         {
  621.             k:=processcommands();
  622.         }
  623.         while (k=1);
  624.     }
  625.     while (k>-1);
  626.     settagged();   // for last screen
  627. }
  628.  
  629. void clearpage()     // initializes page variables
  630. {
  631.     int: i;
  632.     for (i:=1;i<29;i:=i+1)
  633.     {
  634.         p.filename[i]:="";
  635.         p.date[i]:="";
  636.         p.desc[i]:="";
  637.         p.size[i]:=0;
  638.         p.tagged[i]:=FALSE;
  639.     }
  640.  
  641. }
  642.  
  643. unsigned long hextoul(string: strinp, int: ofst)
  644. {
  645.   unsigned long: wlong;
  646.  
  647.   wlong := (unsigned char)strinp[ofst+3];
  648.   wlong := (wlong shl 8)+(unsigned char)strinp[ofst+2];
  649.   wlong := (wlong shl 8)+(unsigned char)strinp[ofst+1];
  650.   return (wlong shl 8)+(unsigned char)strinp[ofst];
  651. }
  652. int hextoi(string: strinp, int: ofst)
  653. {
  654.   int: wint;
  655.  
  656.   wint := (int)strinp[ofst+1];
  657.   return (wint shl 8) + (int)strinp[ofst];
  658. }
  659.  
  660. unsigned int hextoui(string: strinp, int: ofst)
  661. {
  662.   unsigned int: wint;
  663.  
  664.   wint := (unsigned char)strinp[ofst+1];
  665.   return (wint shl 8) + (unsigned char)strinp[ofst];
  666. }
  667.  
  668. unsigned long get_fblk(int: fh)
  669. {
  670.   unsigned long: rc;
  671.   string: gtmp;
  672.     rc := read(fh,gtmp,31);
  673.     HeadType := gtmp[2];
  674.     Flags    := hextoui(gtmp,3);
  675.     HeadSize := hextoui(gtmp,5);
  676.     PackSize := hextoul(gtmp,7);
  677.     UnpSize  := hextoul(gtmp,11);
  678.     HostOS   := gtmp[15];
  679.     FileCRC  := hextoul(gtmp,16);
  680.     FHour    := (hextoui(gtmp,20) shr 11);
  681.     if (FHour < 0) FHour := FHour - 65504;
  682.     FMin     := ((hextoui(gtmp,20) & 0x07e0) shr 5);
  683.     FSec     := (hextoui(gtmp,20) & 0x002f);
  684.     FYear    := (hextoui(gtmp,22) shr 9)+80;
  685.     FMonth   := ((hextoui(gtmp,22) & 0x01e0) shr 5);
  686.     FDay     := (hextoui(gtmp,22) & 0x001f);
  687.     UnpVer   := gtmp[24];
  688.     Method   := gtmp[25];
  689.     NameSize := hextoui(gtmp,26);
  690.     FileAttr := hextoul(gtmp,28);
  691.     NBPos := tell(fh) - rc + HeadSize;
  692.     if (Flags & 0x8000) NBPos := NBPos + PackSize;
  693.     if (rc = 0 or HeadType <> 0x74)
  694.     {
  695.       seek(fh,NBPos,SEEK_SET);
  696.     }
  697.   if (rc > 0 and HeadType = 0x74)
  698.   {
  699.     read(fh,Afname,NameSize);
  700.     seek(fh,NBPos,SEEK_SET);
  701.     rc := rc + NameSize;
  702.     if (HeadType = 0) return(0);
  703.   }
  704.   return(rc);
  705. }
  706.  
  707. unsigned int get_arch(int: fh)
  708. {
  709.   int:    rc;
  710.   string: ftmp;
  711.  
  712.   seek(fh,8,SEEK_SET);
  713.   rc := read(fh,ftmp,13);
  714.   seek(fh,hextoui(ftmp,5)+8,SEEK_SET);
  715.   return hextoui(ftmp,5);
  716. }
  717. void view_cont(string: filespec)
  718. {
  719.   int: Afs, I,  rc;
  720.   long: fsize;
  721.   string:  tmp;
  722.  
  723.   fd := open(farea.downpath+filespec,IOPEN_READ|IOPEN_BINARY);
  724.   if (fd = -1)
  725.   {
  726.     print(COL_WHITE,"Can't find Archive ",farea.downpath+filespec,"\n");
  727.     return;
  728.   }
  729.   rc := read(fd,tmp,6);
  730.   if (tmp <> ARCH_SIGN)
  731.   {
  732.     close(fd);
  733.     input := input + filespec ;
  734.     menu_cmd(MNU_FILE_CONTENTS,"");
  735.     return;
  736.   }
  737.   fsize := filesize(farea.downpath+filespec);
  738.   print("\n");
  739.   print("Contents of Archive ",filespec,"\n\n");
  740.   print(ARCH_TITLE,"\n");
  741.   print(ARCH_LINE,"\n");
  742.   nblock := get_arch(fd);               // position to read first file block
  743.   if (nblock = 0)
  744.   {
  745.     print ("exit");
  746.     return;
  747.   }
  748.   while(get_fblk(fd) > 0)
  749.   {
  750.     if (nblock >= fsize) return;
  751.     if (HeadType = 0x74)
  752.     {
  753.     Afs := 0;
  754.     for ( I := 1 ; I <> strlen(Afname) ; I := I + 1 )
  755.       {
  756.         if (substr(Afname,I,1) = "\\" or substr(Afname,I,1) = "/") Afs := I;
  757.       }
  758.       Afname := substr(Afname,Afs+1,strlen(Afname)-Afs+1);
  759.       print(strpad(Afname,13,' '),strpadleft(ultostr(UnpSize),12,' '));
  760.       print(strpadleft(ultostr(PackSize),9,' ')," ");
  761.       print(FYear,"/",strpadleft(ultostr(FMonth),2,'0'),"/");
  762.       print(strpadleft(ultostr(FDay),2,'0')," ");
  763.       print(strpadleft(ultostr(FHour),2,'0'),":");
  764.       print(strpadleft(ultostr(FMin),2,'0'));
  765.       print("\n");
  766.     }
  767.   }
  768.   close(fd);
  769.   print("\n");
  770. }
  771.  
  772.  
  773. int main()
  774. {
  775.     int: count;
  776.     char: tempchar;
  777.  
  778.     if (filesbbspath()="") // Too bad, files.bbs isn't there!
  779.         {
  780.                 print ("Files.bbs doesn't exist!");
  781.         return 1;
  782.     }
  783.     if (usr.video< (char) 1)
  784.     {
  785.         menu_cmd(MNU_FILE_TITLES,"");
  786.         return 0;
  787.     }
  788.     if (filesize(filesbbspath()) < 10)  // files.bbs is les than 10 bytes
  789.         {                                   // so it is probably empty
  790.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempchar);
  791.             print (AVATAR_GOTO, (char)(4),(char)2,COL_WHITE,"This filearea is empty!");
  792.             getch();
  793.         return 1;
  794.         }
  795.     descr_colour[0]:=COL_WHITE;
  796.     descr_colour[1]:=COL_LCYAN;
  797.     // Opens Files.BBS for reading, filehandle fhandle.
  798.     print (COL_WHITE,"Reading Files.BBS...");
  799.     display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempchar);
  800.     do_it();
  801.  
  802.     print(AVATAR_CLS); // CLS on exit
  803.  
  804.     return 0;
  805. }
  806. void checktagged()
  807. {
  808.     int: i,j,ok, flgs;
  809.     string: tagname,filename;
  810.  
  811.     ok:=tag_queue_size();
  812.     if (ok=0) return;
  813.     for (i:=1;real[i]<32;i:=i+1)
  814.     {
  815.         filename:=strupper(farea.downpath+p.filename[real[i]]);
  816.         for (j:=0;j<ok;j:=j+1)
  817.         {
  818.              tag_get_name(j,flgs,tagname);
  819.         if (tagname=filename)  p.tagged[real[i]]:=TRUE;
  820.         }
  821.     }
  822. }
  823.